// preload images
var dice_1 = new Image();
dice_1.src = "images/dice_1.gif";
var dice_2 = new Image();
dice_2.src = "images/dice_2.gif";
var dice_3 = new Image();
dice_3.src = "images/dice_3.gif";
var dice_4 = new Image();
dice_4.src = "images/dice_4.gif";
var dice_5 = new Image();
dice_5.src = "images/dice_5.gif";
var dice_6 = new Image();
dice_6.src = "images/dice_6.gif";
//
var seg_1 = new Image();
seg_1.src = "images/seg_1.png";
var seg_2 = new Image();
seg_2.src = "images/seg_2.png";
var seg_3 = new Image();
seg_3.src = "images/seg_3.png";
var seg_4 = new Image();
seg_4.src = "images/seg_4.png";
var seg_5 = new Image();
seg_5.src = "images/seg_5.png";
var seg_6 = new Image();
seg_6.src = "images/seg_6.png";
//end preload
//real random for show number
function dice_roll() {
    var d1 = Math.ceil(Math.random() * 6);
    var d2 = Math.ceil(Math.random() * 6);
     document.images[0].src="images/seg_" + d1 + ".png";
     document.images[1].src="images/seg_" + d2 + ".png";
     document.images[2].src="images/dice_" + d1 + ".gif";
     document.images[3].src="images/dice_" + d2 + ".gif";
 }

//roll_it pseudo random for rolling effect
var switch_state = 0;
var output_no = 0;
var this_day = new Date();
var this_second = this_day.getSeconds();
var rb_value = 90;
var led_speed = (this_second + 10);
// trying hard to get a random number

function roll_it(){
//
if (switch_state == 0 )
{
switch_state=1;
this_day = new Date();
this_second = this_day.getSeconds();
led_speed = (this_second + 10);
run_led();
}
//end
}

function run_led() {
window.setTimeout('turn_off()',led_speed);
//end
}

function turn_on() {
dice_roll();
window.setTimeout('turn_off()',led_speed);
//end
}

function turn_off() {
if (led_speed < rb_value)
{
window.setTimeout('turn_on()',led_speed);
led_speed = led_speed + 3 ;
}
else
{
switch_state = 0;
led_speed = 0.1*rb_value;
output_no = 0 //reset counter
}
//end
}


//end of script
